package com.novellotus.iov.carvice.activity;


import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.novellotus.iov.carvice.R;
import com.novellotus.iov.carvice.model.ModifyPasswordModel;
import com.novellotus.iov.carvice.utils.MyUtils;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 修改密码页面
 */
public class ModifyPasswordActivity extends BaseActivity {

    @BindView(R.id.tv_tittle)
    TextView tv_tittle;
    @BindView(R.id.btn_right)
    Button btn_right;
    @BindView(R.id.edt_old_password)
    EditText edt_old_password;
    @BindView(R.id.edt_new_password)
    EditText edt_new_password;
    ModifyPasswordModel modifyPasswordModel;

    @Override
    protected void initContentView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_modify_password);
    }

    @Override
    public void init() {
        tv_tittle.setText("修改密码");
        btn_right.setText("保存");
        modifyPasswordModel = new ModifyPasswordModel(this);
        modifyPasswordModel.setEditOld(edt_old_password);
        modifyPasswordModel.setEditNew(edt_new_password);
        modifyPasswordModel.setConfirm(btn_right);
    }

    @OnClick(R.id.img_back)
    void back() {
        MyUtils.hideInput(this);
        finish();
    }

    @OnClick(R.id.btn_right)
    void saveMessage() {
        JSONObject requestData = new JSONObject();
        try {
            requestData.put("oldPwd", edt_old_password.getText().toString());
            requestData.put("newPwd", edt_new_password.getText().toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        modifyPasswordModel.changePassword(requestData.toString());
    }


}
